<template>
  <div class="list-container">
    <div class="search-wrap clearfix">
      <div class="search-wrap-conditions fl">
        <el-select v-model="listQuery.condition.status" clearable placeholder="请选择状态">
          <el-option
            v-for="item in optionsStatus"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>
      <div class="search-wrap-conditions fl marginL10">
        <el-select v-model="listQuery.condition.typeRole" clearable placeholder="请选择发起者类型">
          <el-option
            v-for="item in optionsInitiator"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </div>
      <div class="search-wrap-conditions fl marginL10">
        <el-input
          v-model="listQuery.condition.title"
          class="input-width"
          placeholder="关键词"
          @keyup.enter.native="init"
        />
      </div>
      <div class="search-wrap-conditions fl marginL10">
        <el-date-picker
          v-model="timer"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
        />
      </div>
      <div class="search-wrap-btn fr">
        <el-button :disabled="loading" @click="resetSearch">重置</el-button>
        <el-button :disabled="loading" type="primary" @click="init">搜索</el-button>
        <!-- <el-button :disabled="loading" type="success" @click="add">添加</el-button> -->
      </div>
    </div>
    <div class="main-wrapper">
      <custom-table :data="listData" :columns="columns">
        <template slot-scope="{row}">
          <el-button type="text" @click="getDetail(row.id)">查看详情</el-button>
        </template>
      </custom-table>
      <pagination :total="total" @pagination="pagination" />
    </div>
  </div>
</template>

<script>
import CustomTable from '@/components/CustomTable/index';
import Pagination from '@/components/Pagination/index';
import { optionsStatus, optionsInitiator } from './mock.js';

import { personPrepareLessonList } from '@/api/activity';

export default {
  name: 'List',
  components: {
    CustomTable,
    Pagination
  },
  data () {
    return {
      loading: false,
      optionsStatus: optionsStatus,
      optionsInitiator: optionsInitiator,
      timer: [],
      listQuery: {
        condition: {
          endTime: '',
          startTime: '',
          status: '',
          title: '',
          typeRole: ''
        },
        pager: {
          page: 1,
          pageSize: 10
        }
      },
      listData: [],
      total: 0,
      columns: [
        { label: '序号', value: 'index' },
        { label: '标题', value: 'title', width: '420px' },
        { label: '创作', value: 'original' },
        { label: '状态', value: 'status' },
        { label: '发布者', value: 'userName' },
        { label: '时间', value: 'createTime', width: '180px' },
        { label: '操作', value: 'todo' }
      ]
    };
  },
  created () {
    this.init();
  },
  methods: {
    async init () {
      this.loading = true;
      this.listQuery.condition.startTime = this.timer && this.timer.length > 0 ? this.timer[0] : null;
      this.listQuery.condition.endTime = this.timer && this.timer.length > 0 ? this.timer[1] : null;
      this.listQuery.condition.title = this.listQuery.condition.title ? this.listQuery.condition.title : null;
      await personPrepareLessonList(this.listQuery).then(res => {
        console.log(res.data);
        this.listData = res.data.records;
        this.total = res.data.total;
        this.loading = true;
      }).catch(error => {
        this.loading = false;
      });
    },
    add () { },

    resetSearch () {
      this.listQuery = {
        condition: {
          keyword: null
        },
        pager: {
          page: 1,
          pageSize: 10
        }
      };
      this.timer = [];
      this.init();
    },
    pagination ({ page, limit }) {
      this.listQuery.pager.page = page;
      this.listQuery.pager.pageSize = limit;
      this.init();
    },
    getDetail (id) {
      // this.$router.push({
      //   path: '/activity/teachingDetail',
      //   query: { param: id }
      // });
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
